#import "EndScreen.h"
#import "State.h"
#import <QuartzCore/QuartzCore.h>
@implementation EndScreen
@synthesize player;

- (id)initWithFrame:(CGRect)frame {
    if ((self = [super initWithFrame:frame])) {
		self.image=[UIImage imageNamed:@"screen_end.png"];
		endTime=CACurrentMediaTime()+10;
		state=S_END;
		currentFrame=0;
		NSArray* fa=[NSArray arrayWithObjects:
					 [UIImage imageNamed:@"screen_end_ray1.png"],
					 [UIImage imageNamed:@"screen_end_ray2.png"],
					 nil];
		[selection =[Sprite alloc] initWithArray:fa mirror:false];
	}
	return self;
}

	- (id) init{
		if([super init]){
			self.image=[UIImage imageNamed:@"screen_end.png"];
			endTime=CACurrentMediaTime()+10;
			state=S_END;
			currentFrame=0;
			NSArray* fa=[NSArray arrayWithObjects:
						 [UIImage imageNamed:@"screen_end_ray1.png"],
						 [UIImage imageNamed:@"screen_end_ray2.png"],
						 nil];
			[selection =[Sprite alloc] initWithArray:fa mirror:false];
			
		}
		return self;
	}
- (void) action:(int) x y:(int) y {
		state=S_TITLE;
	}
    
- (void) drawRect:(CGRect)rect{
	[super drawRect:rect];
    [self.image drawAtPoint:CGPointMake(0,0)];
	[selection paint];
	if(player!=nil)
		[player paint];
	
    }
    - (int) stateMachine {
		currentFrame+=1;
		[selection setCurrentFrame:currentFrame];
		if (endTime< CACurrentMediaTime()) {
			state=S_TITLE;
		}
		return state;	
	}

@end